<template>
  <div class='wx-table'>
    <el-dialog
      title='我要上墙'
      :visible.sync='addWxCodeVisible'
       width='50%' :center='true'>
      <el-form :model='wxCodeForm' ref='wxCodeForm' label-width='80px'>
          <el-form-item prop='myCode' label='我的暗号' size='mini'>
            <el-input v-model='wxCodeForm.myCode' placeholder='我的暗号'></el-input>
          </el-form-item>
        <el-form-item prop='myImg' label='我的二维码' size='mini'>
          <singlePicUpload v-model='wxCodeForm.myImg' @input='inputPicUrlHandler' ></singlePicUpload>
        </el-form-item>
      </el-form>
      <span slot='footer'>
        <el-button size='mini' type='warning' @click='addWxCodeVisible=false'>取消</el-button>
        <el-button size='mini'  type='primary' @click='addWxCode'>确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import singlePicUpload from '@/components/upload/singlePicUpload'
export default {
  name: 'wxCode-add',
  components: {
    singlePicUpload
  },
  data () {
    return {
      addWxCodeVisible: false,
      wxCodeForm: {
        myCode: '',
        myImg: ''
      }
    }
  },
  created: {
  },
  methods: {
    inputPicUrlHandler (url) {
      console.log(url)
      console.log(11112)
      this.wxCodeForm.myImg = url
    },
    init () {
      this.addWxCodeVisible = true
      this.$nextTick(() => {
        this.$refs['wxCodeForm'].resetFields()
      })
    },
    addWxCode () {
      let that = this
      let params = {
        myCode: this.wxCodeForm.myCode,
        myImg: this.wxCodeForm.myImg
      }
      console.log(6666)
      console.log(params)
      this.$api.addWxCode(params).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          that.addWxCodeVisible = false
          that.$emit('refreshDataList')
        } else {
          console.log(res.data)
        }
      }).catch(error => {
        console.log(error)
      })
    }
  }

}
</script>

<style scoped>
  .wx-table{
    margin: auto;
    width: 80%;
  }
  .wx-table{
    width: 100px;
    height: 100px;
    border-radius: 5px;
    overflow: hidden;
  }
  body .el-table th.gutter{
    display: table-cell!important;
  }

</style>
